﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HOOMT.DAO
{
    class MemoryDAO
    {
        public OriginalModelForm findFormById(string id)
        {
            OriginalModelForm returnForm=null;
            MainForm mainForm = SystemVar.mainForm;
            foreach (OriginalModelForm form in mainForm.modelFormList)
            {
                if (id.Equals(form.id))
                {
                    returnForm = form;
                    break;
                }
            }
            return returnForm;
        }

        public OriginalDiagram findDiagramById(string id)
        {
            OriginalDiagram returnDiagram = null;
            MainForm mainForm = SystemVar.mainForm;
            foreach (OriginalModelForm form in mainForm.modelFormList)
            {
                foreach (OriginalDiagram diagram in form.diagramList)
                {
                    if (id.Equals(diagram.id))
                    {
                        returnDiagram = diagram;
                        break;
                    }
                }
            }
            return returnDiagram;
        }

        public OriginalLine findLineById(string id)
        {
            OriginalLine returnLine = null;
            MainForm mainForm = SystemVar.mainForm;
            foreach (OriginalModelForm form in mainForm.modelFormList)
            {
                foreach (OriginalLine line in form.straightlineList)
                {
                    if (id.Equals(line.id))
                    {
                        returnLine = line;
                        break;
                    }
                    
                }
            }
            return returnLine;
        }

        public OriginalDiagram findDiagramByChildForm(OriginalModelForm childForm)
        {
            OriginalDiagram returnDiagram = null;
            MainForm mainForm = SystemVar.mainForm;
            foreach (OriginalModelForm form in mainForm.modelFormList)
            {
                foreach (OriginalDiagram diagram in form.diagramList)
                {
                    if (diagram.ModelForm!=null)
                    {
                        if (diagram.ModelForm.Equals(childForm))
                        {
                            returnDiagram = diagram;
                            break;
                        }
                    }
                  
                }
            }
            return returnDiagram;
        }

        public Attribute findAttrById(string id)
        {
            Attribute rAttr = null;
            MainForm mainForm = SystemVar.mainForm;
            foreach (OriginalModelForm form in mainForm.modelFormList)
            {
                foreach (OriginalDiagram diagram in form.diagramList)
                {
                    if (diagram is ObjectDiagram)
                    {
                        ObjectDiagram objD = (ObjectDiagram)diagram;
                        if (objD.AttributeList!=null)
                        {
                            foreach (Attribute attr in objD.AttributeList)
                            {
                                if (id.Equals(attr.id))
                                {
                                    rAttr = attr;
                                    break;
                                }
                            }
                        }
                    }

                }
            }
            return rAttr;
        }


        public Method findMethodById(string id)
        {
            Method rAttr = null;
            MainForm mainForm = SystemVar.mainForm;
            foreach (OriginalModelForm form in mainForm.modelFormList)
            {
                foreach (OriginalDiagram diagram in form.diagramList)
                {
                    if (diagram is ObjectDiagram)
                    {
                        ObjectDiagram objD = (ObjectDiagram)diagram;
                        if (objD.MethodList != null)
                        {
                            foreach (Method attr in objD.MethodList)
                            {
                                if (id.Equals(attr.id))
                                {
                                    rAttr = attr;
                                    break;
                                }
                            }
                        }
                    }

                }
            }
            return rAttr;
        }
    }
}
